﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace senController.classes
{
    class TrafficLight
    {
        private string name;
        private List<TrafficPlan> trafficPlans;
        private int state;
        private int queueLength;
        private int queueLeft, queueRight, queueStraight;

        public TrafficLight(String name)
        {
            this.name = name;
            this.queueLength = 0;
            this.trafficPlans = new List<TrafficPlan>();
        }

        public void SetTrafficplan(TrafficPlan trafficPlan)
        {
            this.trafficPlans.Add(trafficPlan);
        }

        /// <summary>
        /// Get trafficplan in queue
        /// </summary>
        /// <param name="value">which plan?</param>
        /// <returns>plan</returns>
        public TrafficPlan GetTrafficPlan(int value)
        {
            if (this.trafficPlans[value] != null)
                return this.trafficPlans[value];
            else
                return null;
        }

        /// <summary>
        /// Return all trafficplans associated with trafficlight
        /// </summary>
        /// <returns>List with plans</returns>
        public List<TrafficPlan> GetTrafficPlans()
        {
            return this.trafficPlans;
        }

        public void SetState(int state)
        {
            this.state = state;
        }
        public int GetState()
        {
            return this.state;
        }

        /// <summary>
        /// Add a car to queue.
        /// Case bus: take in consideration the direction
        /// </summary>
        /// <param name="state"></param>
        public void AddCarToQueue(int state = 0)
        {
            switch (state)
            {
                case 4:
                    this.queueLeft++;
                    break;
                case 5:
                    this.queueRight++;
                    break;
                case 6:
                    this.queueStraight++;
                    break;
                default:
                    this.queueLength++;
                    break;
            }            
        }

        /// <summary>
        /// Remove car from queue
        /// Case Bus: take in consideration the direction
        /// </summary>
        /// <param name="direction"></param>
        public void RemoveCarFromQueue(int direction = 0)
        {
            switch (direction)
            {
                case 4:
                    this.queueLeft--;
                    break;
                case 5:
                    this.queueRight--;
                    break;
                case 6:
                    this.queueStraight--;
                    break;
                default:
                    this.queueLength--;
                    break;
            }
        }

        /// <summary>
        /// Get Queue length
        /// Case bus: Take in consideration direction
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
        public int GetQueueLength(int direction = 0)
        {
            int length;
            switch (direction)
            {
                case 4:
                    length = this.queueLeft;
                    break;
                case 5:
                    length = this.queueRight;
                    break;
                case 6:
                    length = this.queueStraight;
                    break;
                default:
                    length = this.queueLength;
                    break;
            }
            return length;
        }

        public string GetName()
        {
            return this.name;
        }
    }
}
